package com.tttn.docbao.adapter;

import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.tttn.docbao.R;
import com.tttn.docbao.until.News;

public class TitleAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<News> arr = new ArrayList<News>();

	public TitleAdapter(Context c, ArrayList<News> arr) {
		this.arr = arr;
		this.context = c;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arr.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return arr.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		LayoutInflater infalInflater = (LayoutInflater) this.context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		parent = (ViewGroup) infalInflater.inflate(R.layout.layout_title, null);
		return parent;
	}

	@SuppressLint("ViewHolder")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater infalInflater = (LayoutInflater) this.context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		convertView = (ViewGroup) infalInflater.inflate(R.layout.layout_title,
				null);
		TextView txttitle = (TextView) convertView.findViewById(R.id.txttitle);
		TextView txtdes = (TextView) convertView.findViewById(R.id.txtdes);
		TextView txtdate = (TextView) convertView.findViewById(R.id.txtdate);

		News b = new News();
		b = (News) getItem(position);
		txttitle.setText(b.getTitle());
		txtdes.setText(b.getDescription());
		txtdate.setText(b.getDate());
		// iv_icon.setImageResource(b.getIcon());
		return convertView;
	}
}